//
//  DBYRoadDetailTableViewCell.m
//  MemoryTravel
//
//  Created by dllo on 15/12/25.
//  Copyright © 2015年 fcx. All rights reserved.
//

#import "DBYRoadDetailTableViewCell.h"

@implementation DBYRoadDetailTableViewCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubViews];
    }
    return self;
}
-(void)createSubViews
{
    self.siteLabel = [[UILabel alloc]init];
    [self.contentView addSubview:self.siteLabel];
    [self.siteLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(5);
        make.top.mas_equalTo(10);
        make.size.mas_equalTo(CGSizeMake(Width - 10, 12));
        
    }];
    
    
    self.roadImageView = [[UIImageView alloc]init];
    [self.contentView addSubview:self.roadImageView];
    [self.roadImageView mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.equalTo(self.siteLabel.mas_left);
        make.top.equalTo(self.siteLabel.mas_bottom).offset(20);
        make.size.mas_equalTo(CGSizeMake(Width - 10, 220));
    }];
    
    self.bigLabel = [[UILabel alloc]init];
    [self.contentView addSubview:self.bigLabel];
    [self.bigLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.siteLabel);
        make.top.equalTo(self.roadImageView.mas_bottom).offset(10);
        make.size.mas_equalTo(CGSizeMake(Width - 10, 1000));
    }];
    self.bigLabel.numberOfLines = 0;

    
}

-(void)setRoadDetailModel:(DBYRoadDetailModel *)roadDetailModel
{
    if (_roadDetailModel != roadDetailModel) {
        _roadDetailModel = roadDetailModel;
    }
    
    
    
    self.l = [NSString stringWithFormat:@"  %@",self.roadDetailModel.entry_name];
    
    [self.roadImageView sd_setImageWithURL:[NSURL URLWithString:self.roadDetailModel.image_url] placeholderImage:[UIImage imageNamed:@"loading.jpg"]];
    
    self.bigLabel.text = self.roadDetailModel.tips;
    self.bigLabel.font = [UIFont systemFontOfSize:17];
    [self.bigLabel sizeToFit];
    
    CGFloat cellHeight = [DBYRoadDetailTableViewCell heightForContent:self.roadDetailModel.tips];
    [self.bigLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
       
        make.left.equalTo(self.siteLabel);
        make.top.equalTo(self.roadImageView.mas_bottom).offset(10);
        make.size.mas_equalTo(CGSizeMake(Width - 10, cellHeight + 10));

    }];
    
    
}
-(void)setS:(NSString *)s{
    if (_s != s) {
        _s = s;
        
    }
    self.siteLabel.text = [NSString stringWithFormat:@"第%@站:%@",self.s,self.l];
    
}


+(CGFloat)heightForContent:(NSString *)content
{
    CGSize size = CGSizeMake(Width - 20, 10000);
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:17.0],NSFontAttributeName, nil];
    CGRect frame = [content boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    return frame.size.height;
    
    
    
}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
